function [] = runCompareResults(runIds, outputFolder)

%%% Add paths
addpath('../general_funcs');
addpath('../model_funcs');
addpath('../model_funcs/dim_specific_funcs/dim2');
addpath('../model_funcs/dim_specific_funcs/dim3');
addpath('../consumerAdoptions');
addpath('../providerAdoptions');
addpath('../providerExits');

outputFolder = createFolderIfNotExist(outputFolder);

NumRuns = length(runIds);
runNames = cell(1,NumRuns);

Ms_consumerAdoptions = cell(NumRuns,1);
Ms_providerAdoptions = cell(NumRuns,1);
Ms_providerExits = cell(NumRuns,1);
for rr = 1:length(runIds)
	runId = runIds(rr);
	if runId == 1; runNames{rr} = 'Week-level model'; end;
	if runId == 101; runNames{rr} = 'Day-level model'; end;
	if runId == 201; runNames{rr} = 'Continuous-time model'; end;
	
	%%% Get input / output paths
	config = getConfig_jointProcess(runId);
	
	% Get config_consumerAdoptions and config_providerAdoptions: necessary input for make_Xdynamic_xxx functions
	indivConfigs.consumerAdoptions = getConfig_consumerAdoptions(config.runId_consumerAdoptions);
	indivConfigs.providerAdoptions  = getConfig_providerAdoptions(config.runId_providerAdoptions);
	indivConfigs.providerExits      = getConfig_providerExits(config.runId_providerExits);
	
	indivRunFolders.providerAdoptions  = config.runFolder_providerAdoptions;
	indivRunFolders.providerExits      = config.runFolder_providerExits;
	indivRunFolders.consumerAdoptions = config.runFolder_consumerAdoptions;
	
	%%% Load data from the 3 submodels to get parameter names
	data = load_data_fullmodel(indivRunFolders);
	paramNames.consumerAdoptions = get_param_names_consumerAdoptions(data.consumerAdoptions);
	paramNames.providerAdoptions  = get_param_names_providerAdoptions(data.providerAdoptions);
	paramNames.providerExits      = get_param_names_providerExits(data.providerExits);
	clear data;
	
	% Load consumer adoptions results
	load(sprintf('%s/results.mat', indivRunFolders.consumerAdoptions), 'params_hat', 'params_ses');
	M1 = reportSubmodelResults(paramNames.consumerAdoptions, params_hat, params_ses, {}, {}, true);
	M1.Properties.VariableNames = {runNames{rr}};
	Ms_consumerAdoptions{rr} = M1;
	clear params_hat params_ses M1;
	
	% Load provider adoptions results
	load(sprintf('%s/results.mat', indivRunFolders.providerAdoptions), 'params_hat', 'params_ses');
	M1 = reportSubmodelResults(paramNames.providerAdoptions, params_hat, params_ses, {}, {}, true);
	M1.Properties.VariableNames = {runNames{rr}};
	Ms_providerAdoptions{rr} = M1;
	clear params_hat params_ses M1;
	
	% Load provider exits results
	load(sprintf('%s/results.mat', indivRunFolders.providerExits), 'params_hat', 'params_ses');
	M1 = reportSubmodelResults(paramNames.providerExits, params_hat, params_ses, {}, {}, true);
	M1.Properties.VariableNames = {runNames{rr}};
	Ms_providerExits{rr} = M1;
	clear params_hat params_ses M1;
end


%%%%% Combine all tables (assuming that the first one contains all parameter names)
for jj = 1:3
	if jj == 1
		Ms = Ms_consumerAdoptions;
		outputFile = sprintf('%s/consumerAdoptions.csv', outputFolder);
	else if jj == 2
		Ms = Ms_providerAdoptions;
		outputFile = sprintf('%s/providerAdoptions.csv', outputFolder);
	else if jj == 3
		Ms = Ms_providerExits;
		outputFile = sprintf('%s/providerExits.csv', outputFolder);
	else
		error('Problem');
	end; end; end;
	
	paramNames = Ms{1}.Properties.RowNames;
	Mout = Ms{1};
	for rr = 2:NumRuns
		Mr = Ms{rr};
		paramNames2 = Mr.Properties.RowNames;
		if ~isequal(paramNames, paramNames2)
			Mr2 = Mout(:,1); Mr2(:,1) = {'-'}; Mr2.Properties.VariableNames = Mr.Properties.VariableNames;
			[flag,myidxes] = ismember(paramNames2, paramNames);
			Mr2(myidxes,1) = Mr;
			Mr = Mr2;
			
			if ~all(ismember(paramNames2, paramNames))
				error('Some paramNames in Mr but not in M1...')
			end
		end
		Mout = [Mout Mr];
	end
	disp(Mout);
	writetable(Mout, outputFile, 'WriteRowNames', true);
end;
	
end
